package com.nku.mason.masonframework.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * 流操作工具类
 * @author Mason
 * @date 2017年3月14日
 */
public final class StreamUtil {
	
	private StreamUtil(){
		//私有构造器，防止外部实例化
	}
	
	private static final Logger LOGGER = LoggerFactory.getLogger(StreamUtil.class);
	
	/**
	 * 从输入流中获取字符串
	 * @param is
	 * @return
	 */
	public static String getString(InputStream is){
		StringBuilder sb = new StringBuilder();
		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(is));
			String line;
			while((line = bf.readLine()) != null){
				sb.append(line);
			}
		} catch (Exception e) {
			LOGGER.error("get string failue",e);
			throw new RuntimeException(e);
		}
		
		return sb.toString();
	}
}
